﻿using System;
using System.Collections.Generic;
using Reviewer.Data;
using Reviewer.Entities;
using Reviewer.Entities.Services;

namespace Reviewer.Business.Services
{
    internal class FrontPageTopService : BaseService, IFrontPageTopService, IFrontPageTopAdminService
    {
        internal FrontPageTopService() : base() { }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }

        #region IFrontPageTopService Members

        public ICollection<FrontPageTop> Find(int maxResults)
        {
            if (maxResults > 0)
            {
                return new FrontPageTopRepository().Select(maxResults);
            }
            else
            {
                return new FrontPageTopRepository().SelectAll();
            }
        }

        public FrontPageTop Find(Guid id)
        {
            return new FrontPageTopRepository().SelectBy(id);
        }

        #endregion

        #region IFrontPageTopAdminService Members

        public FrontPageTop Save(FrontPageTop post)
        {
            if (post.Id == null || post.Id.Equals(Guid.Empty))
            {
                post.Id = Guid.NewGuid();

                return new FrontPageTopRepository().Create(post);
            }

            return new FrontPageTopRepository().Update(post);
        }

        public void Delete(Guid Id)
        {
            new FrontPageTopRepository().Delete(Id);
        }

        #endregion
    }
}
